package com.yfbao.horizon.schedule.tk.controller;


import io.micrometer.core.instrument.Meter;
import io.micrometer.core.instrument.MeterRegistry;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@RestController
@RequestMapping("/test")
public class TestController {
    @Autowired
    private MeterRegistry meterRegistry;

    @GetMapping("")
    public Integer getRulesNum(){
        return null;
    }

    @GetMapping("/mt")
    public List getMetrics(){
        log.info(meterRegistry.getClass().getName());
        List<Meter> meters = meterRegistry.getMeters();
        List<Meter> collect = meters.stream().filter(m -> m.getId().getName().contains("jvm.")).collect(Collectors.toList());
        return collect;
    }


    @GetMapping("/gc")
    public Boolean getGc(){
        log.info("custom:  system gc");
        System.gc();
        return true;
    }
}
